<div id="app">
    <section class="content-header">
        <h1>
            <small>渠道编辑</small>
        </h1>

    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-info">
                    <div class="box-header with-border">


                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 5px">
                                <a href="/admin/channel/index" class="btn btn-sm btn-default" title="渠道列表"><i class="fa fa-list"></i><span class="hidden-xs"> 渠道列表 </span></a>
                            </div>
                        </div>

                        <span>
    <a class="btn btn-sm btn-primary grid-refresh" title="刷新"><i class="fa fa-refresh"></i><span class="hidden-xs"> 刷新</span></a>
    <a class="btn btn-sm btn-primary" onclick="javascript:history.go(-1);" title="返回"> <span class="hidden-xs"> 返回</span></a>
  </span>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form id="addForm" action="/admin/channel/add" method="post" accept-charset="UTF-8" class="form-horizontal" enctype="multipart/form-data" pjax-container>
                        <div class="box-body">
                            <div class="fields-group">

                                <div class="form-group  ">
                                    <label for="cate_name" class="col-sm-2  control-label">渠道名称</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <span class="input-group-addon"><i class="fa fa-pencil fa-fw"></i></span>
                                            <input type="text" id="cha_name" name="cha_name" value="{{$data['cha_name']}}" class="form-control cha_name" placeholder="输入 渠道名称" />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="brand_note" class="col-sm-2  control-label">渠道描述</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <span class="input-group-addon"><i class="fa fa-pencil fa-fw"></i></span>
                                            <input   type="text" id="cha_describe" name="cha_describe" value="{{$data['cha_describe']}}" class="form-control cha_describe" placeholder="输入 渠道描述" />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="brand_note" class="col-sm-2  control-label">APPID</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <span class="input-group-addon"><i class="fa fa-pencil fa-fw"></i></span>
                                            <input   type="text" id="app_id" name="app_id" value="{{$data['app_id']}}" class="form-control app_id" placeholder="输入 APPID" />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="is_official_auth" class="col-sm-2  control-label">是否有排版</label>
                                    <div class="col-sm-8">
                                        <label class="radio-inline">
                                            <input type="radio" name="is_typ" @if($data['is_typ']==1) checked @endif value="1" class="minimal is_typ"    />&nbsp;否&nbsp;&nbsp;
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="is_typ" @if($data['is_typ']==2) checked @endif value="2" class="minimal is_typ"   />&nbsp;是&nbsp;&nbsp;
                                        </label>
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="img" class="col-sm-2  control-label">logo</label>
                                    <div class="col-sm-8">
                                        <input type="file" class="img" name="img"  data-initial-preview="{{$data['logo']}}" />
                                    </div>
                                </div>

                                <div class="form-group  ">
                                    <label for="cha_status" class="col-sm-2  control-label">渠道状态</label>
                                    <div class="col-sm-8">

                                        <select class="form-control cha_status" style="width: 100%;" name="cha_status" data-value="{{$data['cha_status']}}" >
                                            <option value="1" >待审核</option>
                                            <option value="2" >已上线</option>
                                            <option value="3" >已下线</option>
                                            <option value="4" >已删除</option>
                                        </select>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <!-- /.box-body -->

                        <div class="box-footer">
                            @csrf
                            <input type="hidden" name="cha_id" value="{{$data['cha_id']}}">
                            <div class="col-md-2">
                            </div>
                            <div class="col-md-8">
                                <div class="btn-group pull-right">
                                    <button type="button" onclick="tijiao()" class="btn btn-primary">编辑</button>
                                </div>

                                <div class="btn-group pull-left">
                                    <button type="reset" class="btn btn-warning">重置</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>

            </div></div>
    </section>
</div>
<script data-exec-on-popstate>
    $(function () {
        var cha_id="{{$data['cha_id']}}";
        $("input.img").fileinput({
            "overwriteInitial":true,
            "initialPreviewAsData":true,
            "browseLabel":"\u6d4f\u89c8",
            "showRemove":false,
            "showUpload":false,
            "dropZoneEnabled":false,
            "deleteExtraData":{
                "cha_id":cha_id,
                "_token":LA.token,
            },
            "deleteUrl":"http://www.laras.com/admin/channel/delImg",
            "allowedFileTypes":["image"]}) ;

        $('#img').on('filesuccessremove', function(event, id) {
            console.log(id);
            if (some_processing_function(id)) {
                console.log('Uploaded thumbnail successfully removed');
            } else {
                return false;
            }
        });


        //刷新
        $('.grid-refresh').on('click', function() {
            $.pjax.reload('#pjax-container');
            toastr.success('刷新成功 !');
        });
    });


    function tijiao(){
        var data=new FormData($("#addForm")[0]);
        $.ajax({
            url:"/admin/channel/edit",
            type:'post',
            data:data,
            dataType:'json',
            processData: false,
            contentType: false,
            success:function(m){
                if(m.status==1){
                    toastr.success(m.message);
                }else{
                    swal(m.message, '', 'error');
                }
            }
        });
    }
</script>